package sctu.edu.java.year2016.team08.lisonghong.day20160616.chapter15_3;

import sctu.edu.java.year2016.team08.lisonghong.day20160616.chapter12_1.Test;

import javax.swing.*;
import java.awt.*;

/**
 * Created by 松红 on 2016/6/16.
 * 尝试开发一个窗体，在窗体中设计一个进度条，是进度条每次递增滚动。
 */
public class ProgressBar extends JFrame {
    Thread thread;
    int count=0;
    public ProgressBar(){
        final JProgressBar progressBar = new JProgressBar();
        getContentPane().add(progressBar, BorderLayout.NORTH);
        setSize(200,100);
       setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        progressBar.setStringPainted(true);
        thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        thread.sleep(100);
                        progressBar.setValue(++count);
                    } catch (InterruptedException e) {
                        System.out.println("以0.1秒的速度递增！");
                    }
                }
            }
        });
        thread.start();
        thread.interrupt();
    }
    public static void init(JFrame frame, int width, int height) {
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(width, height);
        frame.setVisible(true);
    }

    public static void main(String[] args){
        //init(new InterruptedSwing(), 200, 100);
        new ProgressBar();
    }

}
